//
//  RepairFrame.m
//  智慧小区
//
//  Created by lab603 on 15/6/30.
//  Copyright (c) 2015年 Dreamsoul. All rights reserved.
//

#import "RepairFrame.h"
#import "Repair.h"
#define Top_Padding 5
#define Left_Padding 20
#define typeIconWH 60
@implementation RepairFrame
-(void)setRepair:(Repair *)repair{
    _repair = repair;
    //时间
    CGFloat timeLabelX = Left_Padding;
    CGFloat timeLabelY = Top_Padding;
    CGSize timeLabelSize = [repair.timeOne sizeWithFont:[UIFont systemFontOfSize:13.0]];
    _timeLabelF = (CGRect){{timeLabelX,timeLabelY},timeLabelSize};
    //状态
    NSString *status = nil;
    if (repair.isFixed==0) {
        status = @"已提交";
    }else if (repair.isFixed==1){
        status = @"已完成";
    }else if (repair.isFixed==2){
        status = @"处理中";
    }
    CGSize statusLabelSize = [status sizeWithFont:[UIFont systemFontOfSize:13.0]];
    CGFloat statusLabelX = ScreenWidth - Top_Padding - statusLabelSize.width;
    CGFloat statusLabelY = timeLabelY;
    _statusLabelF = (CGRect){{statusLabelX,statusLabelY},statusLabelSize};
    //分割线
    CGFloat separatorTopX = timeLabelX;
    CGFloat separatorTopY = CGRectGetMaxY(_statusLabelF)+Top_Padding;
    CGSize separatorTopSize = (CGSize){ScreenWidth-Left_Padding,1};
    _separatorTopF = (CGRect){{separatorTopX,separatorTopY},separatorTopSize};
    //类别Icon
    CGFloat typeIconX = Left_Padding;
    CGFloat typeIconY = CGRectGetMaxY(_separatorTopF)+Top_Padding;
    CGSize typeIconSize = (CGSize){typeIconWH,typeIconWH};
    _typeIconF = (CGRect){{typeIconX,typeIconY},typeIconSize};
    //报修类别
    NSString *repairType = nil;
    switch (repair.type) {
        case 1:
            repairType = @"给排水维修";
            break;
        case 2:
            repairType = @"室内电器维修";
            break;
        case 3:
            repairType = @"门窗维修";
            break;
        case 4:
            repairType = @"保洁服务";
            break;
        case 5:
            repairType = @"其他";
            break;
        default:
            break;
    }
    CGFloat repairTypeX = CGRectGetMaxX(_typeIconF)+Left_Padding;
    CGFloat repairTypeY = CGRectGetMaxY(_separatorTopF)+Top_Padding;
    CGSize repairTypeSize = [repairType sizeWithFont:[UIFont systemFontOfSize:16.0]];
    _repairTypeF = (CGRect){{repairTypeX,repairTypeY},repairTypeSize};
    //报修详情
    CGFloat repairDetailX = repairTypeX;
    CGFloat repairDetailY = CGRectGetMaxY(_repairTypeF)+Top_Padding;
    CGSize repairDetailSize = [repair.texts sizeWithFont:[UIFont systemFontOfSize:13.0] constrainedToSize:(CGSize){ScreenWidth - repairDetailX - Left_Padding,MAXFLOAT}];
    _repairDetailF = (CGRect){{repairDetailX,repairDetailY},repairDetailSize};
    //分割线bottom
    CGFloat separatorBottomX = timeLabelX;
    CGFloat separatorBottomY = 0;
    separatorBottomY = (CGRectGetMaxY(_typeIconF)>CGRectGetMaxY(_repairDetailF)?CGRectGetMaxY(_typeIconF):CGRectGetMaxY(_repairDetailF))+Top_Padding;
    CGSize separatorBottomSize = (CGSize){ScreenWidth-Left_Padding,1};
    _separatorBottomF = (CGRect){{separatorBottomX,separatorBottomY},separatorBottomSize};
    //评价按钮
    CGSize evaluateBtnSize = (CGSize){30,20};
    CGFloat evaluateBtnX = ScreenWidth - Left_Padding - evaluateBtnSize.width;
    CGFloat evaluateBtnY = CGRectGetMaxY(_separatorBottomF)+Top_Padding;
    _evaluateBtnF = (CGRect){{evaluateBtnX,evaluateBtnY},evaluateBtnSize};
    //cell的高度
    _cellHeight = CGRectGetMaxY(_evaluateBtnF)+Top_Padding*3;
    if (self.repair.isFixed!=1) {
         _cellHeight = CGRectGetMaxY(_typeIconF)+Top_Padding*4;
    }
}
@end
